﻿#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.Localization;
using PHMEE.Localization;

namespace PHMEE.EnergyEfficiency;

public class CreateUpdateBunkerReportDto : IValidatableObject
{
    /// <summary>
    /// BND 号
    /// </summary>
    [Required]
    public string BunkerDeliveryNoteNumber { get; set; } = null!;

    /// <summary>
    /// UTC 日期，格式 '2024-03-04'
    /// </summary>
    [Required]
    public DateOnly BunkerDeliveryDate { get; set; }
    
    /// <summary>
    /// UTC 时间（精确到分钟），格式 '08:08:00'
    /// </summary>
    [Required]
    public TimeOnly BunkerDeliveryTime { get; set; }

    /// <summary>
    /// 油品
    /// </summary>
    [Required]
    public FuelType FuelType { get; set; }

    /// <summary>
    /// 量
    /// </summary>
    [Required]
    public float Mass { get; set; }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        var localizer = validationContext.GetService(typeof(IStringLocalizer<EnergyEfficiencyResource>)) as IStringLocalizer<EnergyEfficiencyResource>;
        
        if (!EnumValidationHelper.IsValidEnumValue<FuelType>((int)FuelType))
        {
            yield return new ValidationResult(localizer![PHMEEEnergyEfficiencyErrorCodes.InvalidFuelType], [nameof(FuelType)
            ]);
        }
    }
}